package com.easy.user.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.easy.common.bean.SysMenu;
import com.easy.common.service.IMenuService;
import com.easy.common.util.ResultData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RequestMapping("menu")
@RestController
@CrossOrigin
public class MenuController {
    @Autowired
    IMenuService menuService;
    @GetMapping("list")
    public ResultData getAllMenu(SysMenu menu){
        List<SysMenu> list= menuService.getList(menu);
        return ResultData.success(list);
    }

    @GetMapping("page")
    public ResultData getByPage(Page page , SysMenu menu){
        IPage<SysMenu> list= menuService.getListByPage(page,menu);
        return ResultData.success(list);
    }
    @PostMapping("/")
    public ResultData addMenu(@RequestBody  SysMenu menu){
        SysMenu newmenu=menuService.insert(menu);
        return ResultData.success(newmenu);
    }
    @DeleteMapping("/{id}")
    public ResultData deleteMenu(Integer id){
        menuService.delete(id);
        return ResultData.success();
    }
    @PutMapping("/")
    public ResultData editMenu(@RequestBody  SysMenu menu){
        SysMenu newMenu=menuService.update(menu);
        return ResultData.success(newMenu);
    }

}
